import re
my_dict = ({'ELECTION_INTERVAL_YEARS': '1', 
            'BASE_AGGRESSION': '1000', 
            'CAMPAIGN_PERIOD_MONTHS': '1', 
            'STATE_BUREAUCRACY_POP_BASE_COST': '0', 
            'LAW_ENACTMENT_COOLDOWN_DAYS': '0', 
            'STATE_BUREAUCRACY_BASE_COST': '0', 
            'MIN_CONSTRUCTION_EFFICIENCY': '0.99'})

# path
game_path = '/home/h/games/v3'
defines_path = '/game/common/defines/00_defines.txt'
file_path = game_path + defines_path

# read file

with open(file_path, 'r', encoding='utf-8') as file:
    content = file.readlines()

for key in my_dict:
    regular_express = key + ' ' + '=' + ' ' + '.*'
    target = key + ' ' + '=' + ' ' + my_dict[key]
    # print(regular_express, target)
    content = [re.sub(regular_express, target, line) for line in content]


# # write back

with open(file_path, 'w', encoding='utf-8') as file:

    file.writelines(content)


# print("替换完成！")